/* Ejercicio 5.22
   ejer5_22.c */
#include <stdio.h>

/* Prototypes */
void separateDigits( int );

/* function main begins program execution */
int main( void )
{
    int n;

    printf( "Enter a number: " );
    scanf( "%d", &n );
    separateDigits( n );
	return 0; /* indicate that program ended successfully */
} /* end function main */

/* Separate a number between 0 to 32000 in their digits */
void separateDigits( int number )
{
    int divisor = 10000;
    int digito;

    /* Drop all 0s from the beginning */
    digito = number / divisor;
    while ( digito == 0 && number != 0 ) {
        number %= divisor;
        divisor /= 10;
        digito = number / divisor;
    }

    while ( number != 0 ) {
        digito = number / divisor;
        printf( "\t%d", digito );
        number %= divisor;
        divisor /= 10;
    }
    printf( "\n" );
} /* end function separateDigits */
